<?php

if(!defined('IN_NETGORESP')){ exit; }

// Functions - For Random Things!
	function stripslashes_deep($value)
	{
	    
	   $value = is_array($value) ?
	               array_map('stripslashes_deep', $value) :
	               stripslashes($value);
	   return $value;
	   
	}

	function addslashes_deep($value)
	{
	    
	   $value = is_array($value) ?
	               array_map('addslashes_deep', $value) :
	               addslashes($value);
	   return $value;
	   
	}

	function html_deep($value)
	{
	    
	   $value = is_array($value) ?
	               array_map('html_deep', $value) :
	               htmlspecialchars($value);
	   return $value;
	   
	}
	
	function check_status($value)
	{
		return 
		(
			$value == 1 ? 
				"Online" : 
				"Offline"
		);
	}
	
	function check_description($value)
	{
		return
		(
			$value == "" ? 
				"None" : ($value == null ?
				"None" :
				$value
		));
	}
	
	function check_gm($value)
	{
		return
		(
			$value == 0 ? 
				"User" : 
				"GM"
		);
	}
	
	function str_cut($string, $max_length)
	{
		return 
		(
			strlen($string) > $max_length ? 
				substr
				(
					$string, 0, $max_length-strlen
					(
						'...'
					)
				).'...' : 
			$string
		); 
	}
	
	function getUsersOnline($db)
	{
	
    $online_query = $db->sql_query("SELECT `connections` FROM {{table}} ORDER BY id DESC LIMIT 1", "world_stats_network");
    $users_online = $db->sql_array($online_query);
    return $users_online['connections'];
  	
  }
  
  function checkLogin($db, $username, $pass)
  {
    return $db->sql_query("SELECT * FROM {{table}} WHERE name='".$db->sql_escape($username)."' AND password='".md5($pass)."' LIMIT 1", "account");
  }
  
  function addNewUser($db, $name, $pass, $email)
  { 
    $db->sql_query("INSERT INTO {{table}} SET name='$name',password='$pass', email='$email'", "account");
  }
  
  function searchUsers($db, $user)
  {
    return $db->sql_query("SELECT * FROM {{table}} WHERE `name` LIKE \"%$clean_search%\" ORDER BY permissions DESC, name ASC", "account");
  }
  
  function getUsers($db)
  {
    return $db->sql_query("SELECT * FROM {{table}} ORDER BY permissions DESC,name ASC", "account");
  }
  
  function getUserByID($db, $id)
  {
    return $db->sql_query("SELECT * FROM {{table}} WHERE id='".$db->sql_escape($id)."' LIMIT 1", "account");
  }

?>